
LevelGunPick = Class.extend({
    init: function (context, imgs, audios, money, points) {
        this.context = context;
        this.images = imgs;
        this.audios = audios;
        this.money = money;
        this.points = points;
        
        
        this.gameField1 = imgs[10];
        this.gameField2 = imgs[11];
        this.gameField3 = imgs[12];
        
        this.levelAndGunImageCords = 
	    	{
	    		X:90,
	    		Y:200,
	    		width:250,
	    		height:180
	    	}      
                
    },
    
    pickLevel : function () {
        
        var self = this;
        self.context.save();
        self.context.shadowColor = '#000';
        self.context.shadowBlur = 50;
        
        self.context.fillStyle = "white";
        self.context.font ="60px Impact, fantasy";
        self.context.fillText("Pick Level",390,100);
        this.drawImages(self.gameField1,
                            0, 0,
                            900,620,
                            self.levelAndGunImageCords.X, self.levelAndGunImageCords.Y,
                            self.levelAndGunImageCords.width, self.levelAndGunImageCords.height)
        
        if(self.points >= 1000){
            this.drawImages(self.gameField2,
                                0, 0,
                                1024,720,
                                (self.levelAndGunImageCords.X +300), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
        }else{
            this.drawImages(self.gameField2,
                                0, 0,
                                1024,720,
                                (self.levelAndGunImageCords.X +300), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
            self.context.fillStyle = "rgba(255, 255, 255, 0.5)";                 
            self.context.fillRect(  (self.levelAndGunImageCords.X +300), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
                                
        };
        
        
        if(self.points >= 2000){
            
            this.drawImages(self.gameField3,
                                0, 0,
                                1024,720,
                                (self.levelAndGunImageCords.X + 600), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
            
        }else{
            this.drawImages(self.gameField3,
                                0, 0,
                                1024,720,
                                (self.levelAndGunImageCords.X + 600), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
            self.context.fillStyle = "rgba(255, 255, 255, 0.5)";                 
            self.context.fillRect(  (self.levelAndGunImageCords.X + 600), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
                                
        };
        
        self.context.fillStyle = "white";
        self.context.fillText("Level 1",135,500);
        self.context.fillText("Level 2",435,500);
        self.context.fillText("Level 3",735,500);            
        
        self.context.restore();

        document.onmousedown = function (e) {
            
            var mouseCordinateX = e.offsetX;
            var mouseCordinateY = e.offsetY;
            
            self.audios[4].load();
            self.audios[4].play();
            
            self.drawImages(self.images[16],
                            0, 0,
                            1024,720,
                            mouseCordinateX, mouseCordinateY,
                            75, 60);
                            
            setTimeout(function(){
                
                if( mouseCordinateX > self.levelAndGunImageCords.X &&
                    mouseCordinateX < (self.levelAndGunImageCords.X + self.levelAndGunImageCords.width) &&
                    mouseCordinateY > self.levelAndGunImageCords.Y &&
                    mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){

                        self.context.clearRect(0,0,1024,720);
                        self.pickGun(self.gameField1);
                    }
                if(self.points >= 1000){
                    if( mouseCordinateX > (self.levelAndGunImageCords.X + 300)&&
                        mouseCordinateX < (self.levelAndGunImageCords.X + 300 + self.levelAndGunImageCords.width) &&
                        mouseCordinateY > self.levelAndGunImageCords.Y &&
                        mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){

                            self.context.clearRect(0,0,1024,720);
                            self.pickGun(self.gameField2);
                    }
                }
                if(self.points >= 2000){
                    if( mouseCordinateX > (self.levelAndGunImageCords.X + 600) &&
                        mouseCordinateX < (self.levelAndGunImageCords.X + 600 + self.levelAndGunImageCords.width) &&
                        mouseCordinateY > self.levelAndGunImageCords.Y &&
                        mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){

                            self.context.clearRect(0,0,1024,720);
                            self.pickGun(self.gameField3);
                    }
                }
            
            },150);
        };

    },
    
    pickGun : function (level) {
        this.level = level;
        
        var self = this;
        
        self.context.clearRect(0,0,1024,720);
        
        self.context.fillStyle = "white";
        self.context.font ="60px Impact, fantasy";
        self.context.fillText("Pick Gun",400,100);
        
        self.context.shadowColor = '#FFF';
        self.context.shadowBlur = 50;
        
        self.context.drawImage(self.images[13],
                            0, 0,
                            1024,768,
                            self.levelAndGunImageCords.X, self.levelAndGunImageCords.Y,
                            self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
        
        
        if(self.money >= 1000 || this.buyedGuns === 1 ||this.buyedGuns === 2){
            self.context.drawImage(self.images[14],
                                0, 0,
                                1200,720,
                                (self.levelAndGunImageCords.X +300), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
                                
        }else{
            self.context.drawImage(self.images[14],
                                0, 0,
                                1200,720,
                                (self.levelAndGunImageCords.X +300), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
            self.context.fillStyle = "rgba(255, 255, 255, 0.5)";                 
            self.context.fillRect(  (self.levelAndGunImageCords.X +300), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
        }
        
        if(self.money >= 2000 || this.buyedGuns === 2){
            self.context.drawImage(self.images[15],
                                0, 0,
                                824,520,
                                (self.levelAndGunImageCords.X + 600), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
        }else{
            self.context.drawImage(self.images[15],
                                0, 0,
                                824,520,
                                (self.levelAndGunImageCords.X + 600), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
            self.context.fillStyle = "rgba(255, 255, 255, 0.5)";                 
            self.context.fillRect(  (self.levelAndGunImageCords.X + 600), self.levelAndGunImageCords.Y,
                                self.levelAndGunImageCords.width, self.levelAndGunImageCords.height);
        }
                                
                                
        self.context.fillStyle = "white";                        
        self.context.shadowColor = '#000';
        self.context.font ="40px Impact, fantasy";
        self.context.fillText("Handgun M9",105,450);
        self.context.fillText("Mini-UZI",445,450);
        self.context.fillText("AK 47",775,450);
        
        self.context.shadowBlur = 0;
        document.onmousedown = function (e) {
            var mouseCordinateX = e.offsetX;
            var mouseCordinateY = e.offsetY;
            
            self.audios[4].load();
            self.audios[4].play();

            self.context.drawImage(self.images[16],
                            0, 0,
                            1024,720,
                            mouseCordinateX, mouseCordinateY,
                            75, 60);
                            
                var shootedInterval = setInterval(function(){
                    

                    if( mouseCordinateX > self.levelAndGunImageCords.X &&
                        mouseCordinateX < (self.levelAndGunImageCords.X + self.levelAndGunImageCords.width) &&
                        mouseCordinateY > self.levelAndGunImageCords.Y &&
                        mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){
                            self.context.clearRect(mouseCordinateX,mouseCordinateY,200,200);
                            clearInterval(shootedInterval);
                            var game = new Game(self.context,
                                                'container',
                                                self.level,
                                                self.images[7],
                                                self.images,
                                                self.audios,
                                                self.audios[0],
                                                10,
                                                self.money,
                                                self.points,
                                                10);
                        }
                    if(self.money >= 1000 || self.buyedGuns === 1 || self.buyedGuns === 2){    
                        if( mouseCordinateX > (self.levelAndGunImageCords.X + 300)&&
                            mouseCordinateX < (self.levelAndGunImageCords.X + 300 + self.levelAndGunImageCords.width) &&
                            mouseCordinateY > self.levelAndGunImageCords.Y &&
                            mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){
                                self.context.clearRect(mouseCordinateX,mouseCordinateY,200,200);
                                clearInterval(shootedInterval);
                                var game = new Game(self.context,
                                                    'container',
                                                    self.level,
                                                    self.images[8],
                                                    self.images,
                                                    self.audios,
                                                    self.audios[1],
                                                    20,
                                                    self.money,
                                                    self.points);
                            }
                    }
                    if(self.money >= 1000 || self.buyedGuns === 2){
                        if( mouseCordinateX > (self.levelAndGunImageCords.X + 600) &&
                            mouseCordinateX < (self.levelAndGunImageCords.X + 600 + self.levelAndGunImageCords.width) &&
                            mouseCordinateY > self.levelAndGunImageCords.Y &&
                            mouseCordinateY < (self.levelAndGunImageCords.Y + self.levelAndGunImageCords.height)){
                                self.context.clearRect(mouseCordinateX,mouseCordinateY,200,200);
                                clearInterval(shootedInterval); 
                                var game = new Game(self.context,
                                                    'container',
                                                    self.level,
                                                    self.images[9],
                                                    self.images,
                                                    self.audios,
                                                    self.audios[2],
                                                    30,
                                                    self.money,
                                                    self.points);
                            }
                    }
            });
        
        }
    },
    drawImages : function (image,sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
        this.context.drawImage(image,
                            sx, sy,
                            sWidth,sHeight,
                            dx, dy,
                            dWidth, dHeight);
    }
        

    

});


